﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using DCRF.Common.Interface;
using AdminConsole.TreeNodes.Nodes.Collection;

namespace AdminConsole.TreeNodes.Nodes.Single
{
    public class EndPointNode: BaseNode
    {
        public IBlockWeb myWeb = null;
        public Guid myId = Guid.Empty;
        public string myConnectorKey = null;
        public string myEndPointKey = null;
        public string myDescription = null;

        public EndPointNode(IBlockWeb web, Guid id, string key, string description, string secretKey)
        {
            myWeb = web;
            myId = id;
            myConnectorKey = key;
            myDescription = description;
            myEndPointKey = secretKey;
        }

        public override void Attach(TreeNode myNode)
        {
            myNode.Tag = this;
            myNode.SelectedImageKey = myNode.ImageKey = "EndPoint";
            myNode.Text = myDescription;
        }

        protected override void buildChildrenList()
        {
            children.Clear();
        }

        public override List<string> GetCommands(TreeNode myNode)
        {
            List<string> result = new List<string>() { "DET", "REF"};

            return result;
        }

        public override void ExecuteCommand(string cmdKey, TreeNode myNode)
        {
            if (cmdKey == "REF")
            {
                refresh(myNode);
            }
            else if (cmdKey == "DET")
            {
                //detach and remove me
                myWeb[myId][myConnectorKey].DetachEndPoint(myEndPointKey);

                //delete yourself
                myNode.TreeView.SelectedNode = myNode.Parent; 
                (myNode.Parent.Tag as EndPointsNode).ExecuteCommand("REF", myNode.Parent);
            }
        }
    }
}